-- AttribColorM
-- create by panyl
-- 属性颜色处理

module("AttribColorM", package.seeall);

-- 获取属性颜色，目前只有hp、attack会变颜色
function getAttrColor(who, attrib)
    Profiler.funcBegin("getAttrColor");

    -- 默认是白色的
    local color = TextStyleM.getColor("white");

    -- 如果是玩家
    if who.type == OBJECT_TYPE_USER then
        if attrib == "hp" and PropM.getShieldHit() > 0 then
            -- 有护盾加成
            -- 亮绿色
            color = TextStyleM.getColor("light_green");
        elseif attrib == "attack" or attrib == "magic" then
            local buff = PropM.getBuff(who);
            local debuff = PropM.getDebuff(who);
            local special = PropM.getSpecialProp(who);

            local addon = PropM.haveProp(buff, -1, attrib);
            local reduce = PropM.haveProp(debuff, -1, attrib);
            local special = PropM.haveProp(special, -1, attrib);

            -- 如果是攻击，那么还会受到诅咒影响
            if attrib == "attack" and PropM.haveProp(debuff, "curse", 1) then
                reduce = true;
            end

            -- 如果是攻击，那么还会受到腐蚀影响
            if attrib == "attack" and PropM.haveProp(debuff, "corriosion", 1) then
                reduce = true;
            end

            -- 如果是攻击，那么还会受到震慑影响
            if attrib == "attack" and PropM.haveProp(debuff, "frighten", 1) then
                reduce = true;
            end

            -- 如果有增益
            if addon or special then
                -- 当前只有增益
                if not reduce then
                    color = TextStyleM.getColor("light_green");
                end
            elseif reduce then
                -- 当前只有减益
                color = TextStyleM.getColor("light_red");
            end
        end
    elseif who.type == OBJECT_TYPE_MONSTER then
        -- 怪物
        -- 攻击
        if attrib == "attack" then
            local baseAttack = who.dbase:query("attack", 0);
            local attack = who:getAttack();

            local debuff = PropM.getDebuff(who);
            local reduce = PropM.haveProp(debuff, -1, "attack") or PropM.haveProp(debuff, "curse", 1);

            -- 如果宠物当前有减益状态，或者攻击比基础攻击小
            if reduce or attack < baseAttack then
                -- 红色
                color = TextStyleM.getColor("light_red");
            elseif attack > baseAttack then
                -- 攻击比基础攻击高，绿色
                color = TextStyleM.getColor("light_green");
            end
        end
    end

    Profiler.funcEnd("getAttrColor");

    return color;
end

